﻿// Jst.Infrastructure.Web/ServiceCollectionExtensions.cs
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;

namespace Jst.Infrastructure.Web
{
    public static class ServiceCollectionExtensions
    {
        public static IServiceCollection AddApplicationServices(this IServiceCollection services, string? assemblyName = "Jst.Application.dll")
        {
            var assembly = Assembly.LoadFrom(Path.Combine(AppContext.BaseDirectory, assemblyName));
            var serviceTypes = assembly.GetTypes()
                .Where(t => t.IsClass && !t.IsAbstract && t.GetInterfaces().Any());

            foreach (var type in serviceTypes)
            {
                foreach (var interfaceType in type.GetInterfaces())
                {
                    services.AddScoped(interfaceType, type);
                }
            }
            return services;
        }
    }
}

